home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer 2.0 / Internet Surfer 2.0 (Wayzata Technology) (1996).iso / pc / faq / faqs / msds_faq / part2 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  28.0 KB

  1. Xref: bloom-picayune.mit.edu comp.os.msdos.programmer:18889 news.answers:4712
  2. Path: bloom-picayune.mit.edu!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!mcsun!uknet!doc.ic.ac.uk!agate!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ncoast!brown
  3. From: brown@NCoast.ORG (Stan Brown)
  4. Newsgroups: comp.os.msdos.programmer,news.answers
  5. Subject: comp.os.msdos.programmer FAQ part 2 of 4
  6. Message-ID: <msdos-faq.921220.2@NCoast.ORG>
  7. Date: 20 Dec 92 20:13:14 GMT
  8. Expires: Wed, 3 Feb 1993 20:13:14 GMT
  9. References: <msdos-faq.921220.1@NCoast.ORG>
  10. Followup-To: comp.os.msdos.programmer
  11. Organization: Oak Road Systems, Cleveland Ohio USA
  12. Lines: 589
  13. Approved: news-answers-request@MIT.Edu
  14. Supersedes: <msdos-faq.921205.2@NCoast.ORG>
  15.  
  16. Archive-name: msdos-programmer-faq/part2
  17. Last-modified: 20 December 1922
  18.  
  19. (continued from part 1)         (no warranty on the code or information)
  20.  
  21. If the posting date is more than six weeks in the past, see instructions
  22. at the end of this article for how to get an updated copy.
  23.  
  24.             Copyright (C) 1992  Stan Brown, Oak Road Systems
  25.  
  26.  
  27. section 1. General questions
  28. ============================
  29.  
  30. Q101. Why won't my code work?
  31.  
  32.     First you need to try to determine whether the problem is in your
  33.     use of the programming language or in your use of MSDOS and your PC
  34.     hardware.  (Your manual should tell you which features are standard
  35.     and which are vendor- or MSDOS- or PC-specific.  You _have_ read
  36.     your manual carefully, haven't you?)
  37.  
  38.     If the feature that seems to be working wrong is something related
  39.     to your PC hardware or to the internals of MS-DOS, this group is the
  40.     right place to ask.  (Please check this list first, to make sure
  41.     your question isn't already answered.)
  42.  
  43.     On the other hand, if your problem is with the programming language,
  44.     the comp.lang hierarchy (including comp.lang.pascal and comp.lang c)
  45.     is probably a better resource.  Please read the other group's FAQ
  46.     list thoroughly before posting.  (These exist in comp.lang.c,
  47.     comp.lang.c++, comp.lang.modula3, comp.lang.lisp, comp.lang.perl;
  48.     they may exist in other groups as well.)  It's almost never a good
  49.     idea to crosspost between this group and a language group.
  50.  
  51.     Before posting in either place, try to make your program as small as
  52.     possible while still exhibiting the bad behavior.  Sometimes this
  53.     alone is enough to show you where the trouble is.  Also edit your
  54.     description of the problem to be as short as possible.  This makes
  55.     it look more like you tried to solve the problem on your own, and
  56.     makes people more inclined to try to help you.
  57.  
  58.     When you do post a question, it's good manners to say "email please;
  59.     I'll post a summary."  Then everybody else in the group doesn't have
  60.     to read ten virtually identical responses.  Of course, then you have
  61.     to follow through.  A summary is not simply pasting together all the
  62.     email you received.  Instead, write your own (brief) description of
  63.     the solution:  this is the best way to make sure you really
  64.     understand it.  Definitely don't repost people's cute signatures.
  65.  
  66. Q102. What is this newsgroup about?
  67.  
  68.     comp.os.msdos.programmer (comp.sys.ibm.pc.programmer until September
  69.     1990) concerns programming for MS-DOS systems.  The article "USENET
  70.     Readership report for Nov 92" in news.lists shows 42,000 readers of
  71.     this newsgroup worldwide.  Traffic was 1090.7 Kbytes (exclusive of
  72.     crossposts), comprised in 611 articles.
  73.  
  74.     Much of our traffic is about language products (chiefly from Borland
  75.     and Microsoft).  More programming topics focus on C than on any one
  76.     other language.
  77.  
  78.     Since most MS-DOS systems run on hardware that is roughly compatible
  79.     with the IBM PC, on Intel 8088, 80188, or 80x86 chips, we tend to
  80.     get a lot of questions and answers about programming other parts of
  81.     the hardware.
  82.  
  83. Q103. What's the difference from comp.sys.ibm.pc.programmer?
  84.  
  85.     c.s.i.p.programmer is the old name of comp.os.msdos.programmer, and
  86.     has been obsolete since September 1990.  However, many systems have
  87.     not removed the old group, or have removed it but aliased it to the
  88.     new name.  This means that some people still think they're posting
  89.     to c.s.i.p.programmer even though they're actually posting to
  90.     c.o.m.programmer.
  91.  
  92.     You can easily verify the non-existence of c.s.i.p.programmer by
  93.     reference to the "List of Active Newsgroups" posted to news.groups.
  94.     It's available as /pub/usenet/news.answers/active-newsgroups/part1
  95.     from the archives (see "Where are FAQ lists archived?" in section C,
  96.     "More information").
  97.  
  98. Q104. What other newsgroups should I know about?
  99.  
  100.     Your best bet is to read the periodic information postings in the
  101.     comp.binaries.ibm.pc newsgroup.  Specially helpful articles:
  102.         Using the comp.binaries.ibm.pc.d groups
  103.         Beginner's guide to binaries
  104.         Starter kit
  105.         About archives and archivers
  106.     Please wait for these articles to come around; don't post a request.
  107.  
  108.     Also check out news.announce.newusers, even if you're not a new
  109.     user.  You may be surprised how much useful information is in the
  110.     monthly postings there.  Lots of old-timers also get useful stuff
  111.     from news.newusers.questions, especially the periodic postings.
  112.  
  113.     Remember that it's good manners to subscribe to any newsgroup and
  114.     read it for a while before you post a question.  When you post, it's
  115.     also good manners to ask for replies to be emailed and then to post
  116.     a summary, which you've edited down to the absolute minimum size.
  117.  
  118.     You may also be interested in the following newsgroups.  Caution:
  119.     Some of them have specialized charters; you'll probably get (and
  120.     deserve) some flames if you post to an inappropriate group.
  121.  
  122.     - misc.forsale.computers and misc.forsale.computers.pc-clone are
  123.       where you post notices of equipment, software, or computer books
  124.       that you want to sell.  Please don't post or crosspost those
  125.       notices to comp.os.msdos.programmer.
  126.  
  127.     - comp.os.ms-windows.programmer.tools and ...misc (formerly part of
  128.       comp.windows.ms.programmer):  Similar to this group, but focus
  129.       on programming for the MS-Windows platform.
  130.  
  131.     - comp.sys.ibm.pc.hardware is for more hardware-oriented discussions
  132.       of the machines that run DOS.
  133.  
  134.     - comp.binaries.ibm.pc.wanted: AFTER you have looked in the other
  135.       groups, this is the place to post a request for a particular
  136.       binary program.
  137.  
  138.     - comp.binaries.msdos.announce (moderated) explains how to use the
  139.       archive sites, especially garbo and Simtel, and lists files
  140.       uploaded to them.  Discussions belong in comp.binaries.msdos.d,
  141.       which replaced comp.binaries.ibm.pc.archives.
  142.  
  143.     - comp.binaries.ibm.pc.d is for discussions about programs posted in
  144.       comp.binaries.ibm.pc, and only those programs.  This is a good
  145.       place to report bugs in the programs, but not to ask where to find
  146.       them (see cbip.wanted, above).  cbip.d is NOT supposed to be a
  147.       general PC discussion group.
  148.  
  149.     - comp.sources.misc: a moderated group for source code for many
  150.       computer systems.  It tends to get lots of Unix stuff, but you may
  151.       also pick up some DOS-compatible code here.
  152.  
  153.     - alt.sources: an unmoderated group for source code.  Guidelines are
  154.       posted periodically.
  155.  
  156.     - Turbo Vision is a mailing list, not a newsgroup; send email to
  157.       listserv@vtvm1.cc.vt.edu if you want to subscribe.
  158.  
  159.  
  160. section 2. Compile and link
  161. ===========================
  162.  
  163. Q201. What the heck is "DGROUP > 64K"?
  164.  
  165.     DGROUP is a link-time group of data segments, and the compiler
  166.     typically generates code that expects DS to be pointing to DGROUP.
  167.     (Exception: Borland's huge model has no DGROUP.)
  168.  
  169.     Here's what goes into DGROUP:
  170.  
  171.     - tiny model (all pointers near):  DGROUP holds the entire program.
  172.  
  173.     - small and medium models (data pointers near):  DGROUP holds all
  174.       globals and static variables including string literals, plus the
  175.       stack and the heap.
  176.  
  177.     - large, compact, and huge models in Microsoft (data pointers far):
  178.       DGROUP holds only initialized globals and static variables
  179.       including string literals, plus the stack and the near heap.
  180.  
  181.     - large and compact models in Borland (data pointers far): DGROUP
  182.       holds initialized and uninitialized globals and static variables
  183.       including string literals, but not the stack or heap.
  184.  
  185.     - huge model in Borland (data pointers far): there is no DGROUP, so
  186.       the 64K limit doesn't apply.
  187.  
  188.     In all of the above, which is to say all six models in Microsoft C
  189.     and all but huge in Borland C, DGROUP is limited to 64K including
  190.     string literals (which are treated as static data).  This limitation
  191.     is due to the Intel CPU's segmented architecture.
  192.  
  193.     See the next Q for possible remedies.
  194.  
  195.     For more information, see topics like "memory models" and "memory
  196.     management" in the index of your compiler manual.  Also see
  197.     TI738.ASC in PD1:<MSDOS.TURBO-C>BCHELP10.ZIP at Simtel for an
  198.     extended general discussion of memory usage in Borland C programs,
  199.     of which much applies to any C compiler in DOS.
  200.  
  201. Q202. How do I fix "automatic data segment exceeds 64K" or "stack plus
  202.       data exceed 64K"?
  203.  
  204.     These messages are a variation of "DGROUP > 64K".  For causes,
  205.     please see the preceding Q.
  206.  
  207.     If you get this error in tiny model, your program is simply too big
  208.     and you must use a different memory model.  If you get this link
  209.     error in models S, C, M, L, or Microsoft's H, there are some things
  210.     you can do.  (This error can't occur in Borland's huge model.)
  211.  
  212.     If you have one or two big global arrays, simply declare them far.
  213.     The compiler takes this to mean that any references to them will use
  214.     32-bit pointers, so they'll be in separate segments and no longer
  215.     part of DGROUP.
  216.  
  217.     Or you can use the /Gt[number] option with Microsoft or -Ff[=size]
  218.     with Borland C++ 2.0 and up.  This will automatically put variables
  219.     above a certain size into their own segments outside of DGROUP.
  220.  
  221.     Yet another option is to change global arrays to far pointers.  Then
  222.     at the beginning of your program, allocate them from the far heap
  223.     (_fmalloc in Microsoft, farmalloc in Borland).
  224.  
  225.     Finally, you can change to huge model (with Borland compilers, not
  226.     Microsoft).  Borland's H model still uses far pointers by default,
  227.     but "sets aside the [64K] limit" and has no DGROUP group, according
  228.     to the BC++ 2.0 Programmer's Guide.  Microsoft's H model does use
  229.     huge data pointers by default but retains DGROUP and its 64K limit,
  230.     so switching to the H model doesn't buy you anything if you have
  231.     DGROUP problems.
  232.  
  233. Q203. Will Borland C code and Microsoft C code link together?
  234.  
  235.     Typically this question is asked by someone who owns compiler A and
  236.     is trying to write code to link with a third-party library that was
  237.     compiled under compiler B.
  238.  
  239.     The answer to the question is, Not in general.  Here are some of the
  240.     reasons:
  241.  
  242.     - "Helper" functions (undocumented functions for stack checking,
  243.       floating-point arithmetic, and operations on longs) differ between
  244.       the two compilers.
  245.  
  246.     - The compilers may embed instructions in the object code that tell
  247.       the linker to look for their own run-time libraries.
  248.  
  249.     Those problems will generate link-time errors.  Others may not show
  250.     up until run time:
  251.  
  252.     - Borland's compact, large, and huge models don't assume DS=SS, but
  253.       Microsoft's do.  The -Fs option on the Borland compiler, or one of
  254.       the /A options on Microsoft, should take care of this problem --
  255.       once you know that's what's going on.
  256.  
  257.     - Check conventions for ordering and packing structure members, and
  258.       for alignment of various types on byte, word, paragraph, or other
  259.       boundaries.  Again, you can generally adjust your code to match if
  260.       you know what conventions were used in compiling the "foreign"
  261.       libraries.
  262.  
  263.     - Check the obvious and make sure that your code was compiled under
  264.       the same memory model as the code you're trying to link with.
  265.       (That's necessary, but no guarantee.  Microsoft and Borland don't
  266.       use exactly the same conventions for segments and groups,
  267.       particularly in the larger memory models.)
  268.  
  269.     That said, there are some circumstances where you can link hybrids.
  270.     Your best chance of success comes if you avoid longs and floating
  271.     point, use only 16-bit pointers, suppress stack checking, and
  272.     specify all libraries used in the link.
  273.  
  274. Q204. Why did my program bomb at run time with "floating point formats
  275.       not linked"?
  276.  
  277.     First, is that the actual message, or did it say "floating point not
  278.     loaded"?  If it was the latter, see the next Q.
  279.  
  280.     You're probably using a Borland compiler for C or C++ (including
  281.     Turbo C and Turbo C++).  Borland's compilers try to be smart and not
  282.     link in the floating-point (f-p) library unless you need it.  Alas,
  283.     they all get the decision wrong.  One common case is where you don't
  284.     call any f-p functions, but you have %f or other f-p formats in
  285.     scanf/printf calls.  The cure is to call an f-p function, or at
  286.     least force one to be present in the link.
  287.  
  288.     To do that, define this function somewhere in a source file but
  289.     don't call it:
  290.  
  291.         static void forcefloat(float *p)
  292.             { float f = *p; forcefloat(&f); }
  293.  
  294.     It doesn't have to be in the module with the main program, as long
  295.     as it's in a module that will be included in the link.
  296.  
  297.     A new solution for Borland C++ 3.0 was posted, but I don't own the
  298.     product and have not been able to verify it.  Insert these
  299.     statements in your program:
  300.  
  301.         extern unsigned _floatconvert;
  302.         #pragma extref _floatconvert
  303.  
  304. Q205. Why did my program bomb with "floating point not loaded"?
  305.  
  306.     That is Microsoft C's run-time message when the code requires a
  307.     numeric coprocessor but your computer doesn't have one installed.
  308.  
  309.     If the program is yours, relink it using the xLIBCE or xLIBCA
  310.     library (where x is the memory model).
  311.  
  312. Q206. How can I change the stack size in Borland's C compilers?
  313.  
  314.     In Turbo C, Turbo C++, and Borland C++, you may not find "stack
  315.     size" in the index but the global variable _stklen should be there.
  316.     The manual will instruct you to put a statement like
  317.  
  318.         extern unsigned _stklen = 54321U;
  319.  
  320.     in your code, outside of any function.  You must assign the value
  321.     right in the extern statement; it won't work to assign a value at
  322.     run time.  (The "extern" in this context isn't ANSI C and ought not
  323.     to be required, but the above statement is a direct quote from the
  324.     Library Reference manual of Borland C++ 2.0.)  The linker may give
  325.     you a duplicate symbol warning, which you can ignore.
  326.  
  327. Q207. What's the format of an .OBJ file?
  328.  
  329.     Here's what I've been told, though I have verified any of these
  330.     references myself:
  331.  
  332.     - base .OBJ format:  Intel's document number #121748-001, {8086
  333.       Relocatable Object Module Formats}.  (Note however that both
  334.       Microsoft and Borland formats have extended the .OBJ format.)
  335.  
  336.     - Microsoft-specific .OBJ formats:  a "Microsoft OMF Specification"
  337.       (document number ??), as well as a section in the MS-DOS
  338.       encyclopedia.
  339.  
  340.     - A "tutorial on the .OBJ format" comes with the VAL experimental
  341.       linker, which is VAL-LINK.ARC in PD1:<MSDOS.PGMUTL> at Simtel.
  342.  
  343.     If you have specific references, either to fpt-able documents or to
  344.     published works (author, title, order number or ISBN), please email
  345.     them to brown@ncoast.org for inclusion in the next edition of this
  346.     list.
  347.  
  348. Q208. What's the format of an .EXE header?
  349.  
  350.     See pages 349-350 of {PC Magazine}'s June 30, 1992 issue (xi:12) for
  351.     the old and new formats.  For a more detailed layout, look under INT
  352.     21 function 4B in Ralf Brown's interrupt list.  Ralf Brown's list
  353.     includes extensions for Borland's TLINK and Borland debugger info.
  354.  
  355.     Among the books that detail formats of executable files are {DOS
  356.     Programmer's Reference: 2d Edition} by Terry Dettman and Jim Kyle,
  357.     ISBN 0-88022-458-4; and {Microsoft MS-DOS Programmer's Reference},
  358.     ISBN 1-55615-329-5.
  359.  
  360. Q209. What's the difference between .COM and .EXE formats?
  361.  
  362.     To oversimplify:  a .COM file is a direct image of core, and an .EXE
  363.     file will undergo some further relocation when it is run (and so it
  364.     begins with a relocation header).  A .COM file is limited to 64K for
  365.     all segments combined, but an .EXE file can have as many segments as
  366.     your linker will handle and be as large as RAM can take.
  367.  
  368.     The actual file extension doesn't matter.  DOS knows that a file
  369.     being loaded is in .EXE format if its first two bytes are MZ or ZM;
  370.     otherwise it is assumed to be in .COM format.  For instance, I am
  371.     told that DR-DOS 6.0's COMMAND.COM is in .EXE format.
  372.  
  373.  
  374. section 3. Keyboard
  375. ===================
  376.  
  377. Q301. How can I read a character without echoing it to the screen, and
  378.       without waiting for the user to press the Enter key?
  379.  
  380.     The C compilers from Microsoft and Borland offer getch (or getche to
  381.     echo the character); Turbo Pascal has ReadKey.
  382.  
  383.     In other programming languages, load 8 in register AH and execute
  384.     INT 21; AL is returned with the character from standard input
  385.     (possibly redirected).  If you don't want to allow redirection, or
  386.     you want to capture Ctrl-C and other special keys, use INT 16 with
  387.     AH=10; this will return the scan code in AH and ASCII code (if
  388.     possible) in AL, except that AL=E0 with AH nonzero indicates one of
  389.     the grey "extended" keys was pressed.  (If your BIOS doesn't
  390.     support the extended keyboard, use INT 16 function 0 not 10.)
  391.  
  392. Q302. How can I find out whether a character has been typed, without
  393.       waiting for one?
  394.  
  395.     In Turbo Pascal, use KeyPressed.  Both Microsoft C and Turbo C offer
  396.     the kbhit( ) function.  All of these tell you whether a key has been
  397.     pressed.  If no key has been pressed, they return that information
  398.     to your program.  If a keystroke is waiting, they tell your program
  399.     that but leave the key in the input buffer.
  400.  
  401.     You can use the BIOS call, INT 16 function 01 or 11, to check
  402.     whether an actual keystroke is waiting; or the DOS call, INT 21
  403.     function 0B, to check for a keystroke from stdin (subject to
  404.     redirection).  See Ralf Brown's interrupt list.
  405.  
  406. Q303. How can I disable Ctrl-C/Ctrl-Break and/or Ctrl-Alt-Del?
  407.  
  408.     You can download the file PD1:<MSDOS.KEYBOARD>CADEL.ZIP from Simtel.
  409.     It contains a TSR to disable those keys, with source code in ASM.
  410.  
  411.     To disable only Ctrl-Alt-Del (actually, to change the boot keys to
  412.     leftShift-Alt-Del), use DEBOOT.COM.  Along with KEYKILL.COM, which
  413.     lets you disable up to three keys of your choice, it is at Simtel in
  414.     the file PD1:<MSDOS.KEYBOARD>KEYKILL.ARC.
  415.  
  416.     C programmers who simply want to make sure that the user can't
  417.     Ctrl-Break out of their program can use the ANSI-standard signal( )
  418.     function; the Borland compilers also offer ctrlbrk( ) for handling
  419.     Ctrl-Break.  However, if your program uses normal DOS input, the
  420.     characters ^C will appear on the screen when the user presses Ctrl-C
  421.     or Ctrl-Break.  There are many ways to work around that, including:
  422.     use INT 21 function 7, which allows redirection but doesn't display
  423.     the ^C (or echo any other character, for that matter); or use INT 16
  424.     function 0 or 10; or call _bios_keybrd( ) in MSC or bioskey( ) in
  425.     BC++; or hook INT 9 to discard Ctrl-C and Ctrl-Break before the
  426.     regular BIOS keyboard handler sees them; etc., etc.
  427.  
  428.     You should be aware that Ctrl-C and Ctrl-Break are processed quite
  429.     differently internally.  Ctrl-Break, like all keystrokes, is
  430.     processed by the BIOS code at INT 9 as soon as the user presses the
  431.     keys, even if earlier keys are still in the keyboard buffer:  by
  432.     default the handler at INT 1B is called.  Ctrl-C is not special to
  433.     the BIOS, nor is it special to DOS functions 6 and 7; it _is_
  434.     special to DOS functions 1 and 8 when at the head of the keyboard
  435.     buffer.  You will need to make sure BREAK is OFF to prevent DOS
  436.     polling the keyboard for Ctrl-C during non-keyboard operations.
  437.  
  438.     Some good general references are {Advanced MS-DOS} by Ray Duncan,
  439.     ISBN 1-55615-157-8; {8088 Assembler Language Programming:  The IBM
  440.     PC}, ISBN 0-672-22024-5, by Willen & Krantz; and {COMPUTE!'s Mapping
  441.     the IBM PC}, ISBN 0-942386-92-2.
  442.  
  443. Q304. How can I disable the print screen function?
  444.  
  445.     There are really two print screen functions:  1) print current
  446.     screen snapshot, triggered by PrintScreen or Shift-PrtSc or
  447.     Shift-grey*, and 2) turn on continuous screen echo, started and
  448.     stopped by Ctrl-P or Ctrl-PrtSc.
  449.  
  450.     1) Screen snapshot to printer
  451.        --------------------------
  452.  
  453.     The BIOS uses INT 5 for this.  Fortunately, you don't need to mess
  454.     with that interrupt handler.  The standard handler, in BIOSes dated
  455.     December 1982 or later, uses a byte at 0040:0100 (alias 0000:0500)
  456.     to determine whether a print screen is currently in progress.  If it
  457.     is, pressing PrintScreen again is ignored.  So to disable the screen
  458.     snapshot, all you have to do is write a 1 to that byte.  When the
  459.     user presses PrintScreen, the BIOS will think that a print screen is
  460.     already in progress and will ignore the user's keypress.  You can
  461.     re-enable PrintScreen by zeroing the same byte.
  462.  
  463.     Here's some simple code:
  464.  
  465.         void prtsc_allow(int allow) /* 0=disable, nonzero=enable */ {
  466.             unsigned char far* flag = (unsigned char far*)0x00400100UL;
  467.             *flag = (unsigned char)!allow;
  468.         }
  469.  
  470.     2) Continuous echo of screen to printer
  471.        ------------------------------------
  472.  
  473.     If ANSI.SYS is loaded, you can easily disable the continuous echo of
  474.     screen to printer (Ctrl-P or Ctrl-PrtSc).  Just redefine the keys by
  475.     "printing" strings like these to the screen (BASIC print, C printf,
  476.     Pascal Write statements, or ECHO command in batch files):
  477.  
  478.         <27>[0;114;"Ctrl-PrtSc disabled"p
  479.         <27>[16;"^P"p
  480.  
  481.     Change <27> in the above to an Escape character, ASCII 27.
  482.  
  483.     If you haven't installed ANSI.SYS, I can't offer an easy way to
  484.     disable the echo-screen-to-printer function.  Please send any tested
  485.     solutions to brown@ncoast.org and I'll add them to this list.
  486.  
  487.     Actually, you might not need to disable Ctrl-P and Ctrl-PrtSc.  If
  488.     your only concern is not locking up your machine, when you see the
  489.     "Abort, Retry, Ignore, Fail" prompt just press Ctrl-P again and then
  490.     I.  As an alternative, install one of the many print spoolers that
  491.     intercept printer-status queries and always return "Printer ready".
  492.  
  493. Q305. How can my program turn NumLock (CapsLock, ScrollLock) on or off?
  494.  
  495.     You need to twiddle bit 5, 6, or 4 of location 0040:0017.  Here's
  496.     some code:  lck( ) turns on a lock state, and unlck( ) turns it off.
  497.     (The status lights on some keyboards may not reflect the change.  If
  498.     yours is one, call INT 16 function 2, "get shift status", and that
  499.     may update them.  It will certainly do no harm.)
  500.  
  501.         #define NUM_LOCK  (1 << 5)
  502.         #define CAPS_LOCK (1 << 6)
  503.         #define SCRL_LOCK (1 << 4)
  504.         void lck(int shiftype) {
  505.             char far* kbdstatus = (char far*)0x00400017UL;
  506.             *kbdstatus |= (char)shiftype;
  507.         }
  508.         void unlck(int shiftype) {
  509.             char far* kbdstatus = (char far*)0x00400017UL;
  510.             *kbdstatus &= ~(char)shiftype;
  511.         }
  512.  
  513. Q306. How can I speed up the keyboard's auto-repeat?
  514.  
  515.     The keyboard speed has two components: delay (before a key that you
  516.     hold down starts repeating) and typematic rate (the speed once the
  517.     key starts repeating).  Most BIOSes since 1986 let software change
  518.     the delay and typematic rate by calling INT 16 function 3, "set
  519.     typematic rate and delay"; see Ralf Brown's interrupt list.  If you
  520.     have DOS 4.0 or later, you can use the MODE CON command that you'll
  521.     find in your DOS manual.
  522.  
  523.     On 83-key keyboards (mostly XTs), the delay and typematic rate can't
  524.     easily be changed.  According to the {PC Magazine} of 15 Jan 1991,
  525.     page 409, to adjust the typematic rate you need "a memory-resident
  526.     program which simply '[watches]' the keyboard to see if you're
  527.     holding down a key ... and after a certain time [starts] stuffing
  528.     extra copies of the held-down key into the buffer."  No source code
  529.     is given in that issue; but I'm told that the QUICKEYS utility that
  530.     {PC} published in 1986 does this sort of watching; you can download
  531.     source and object code in PD1:<MSDOS.PCMAG>VOL5N05.ARC from Simtel.
  532.  
  533. Q307. What is the SysRq key for?
  534.  
  535.     There is no standard use for the key.  The BIOS keyboard routines in
  536.     INT 16 simply ignore it; therefore so do the DOS input routines in
  537.     INT 21 as well as the keyboard routines in libraries supplied with
  538.     high-level languages.
  539.  
  540.     When you press or release a key, the keyboard triggers hardware line
  541.     IRQ1, and the CPU calls INT 9.  INT 9 reads the scan code from the
  542.     keyboard and the shift states from the BIOS data area.
  543.  
  544.     What happens next depends on whether your PC's BIOS supports an
  545.     enhanced keyboard (101 or 102 keys).  If so, INT 9 calls INT 15
  546.     function 4F to translate the scan code.  If the translated scan code
  547.     is 54 hex (for the SysRq key) then INT 9 calls INT 15 function 85
  548.     and doesn't put the keystroke into the keyboard buffer.  The default
  549.     handler of that function does nothing and simply returns.  (If your
  550.     PC has an older BIOS that doesn't support the extended keyboards,
  551.     INT 15 function 4F is not called.  Early ATs have 84-key keyboards,
  552.     so their BIOS calls INT 15 function 85 but nor 4F.)
  553.  
  554.     Thus your program is free to use SysRq for its own purposes, but at
  555.     the cost of some programming.  You could hook INT 9, but it's
  556.     probably easier to hook INT 15 function 85, which is called when
  557.     SysRq is pressed or released.
  558.  
  559. Q308. How can my program tell what kind of keyboard is on the system?
  560.  
  561.     Ralf Brown's Interrupt List includes MEMORY.LST, a detailed
  562.     breakdown by Robin Walker of the contents of the BIOS system block
  563.     that starts at 0040:0000.  Bit 4 of byte 0040:0096 is "1=enhanced
  564.     keyboard installed".  C code to test the keyboard type:
  565.         char far *kbd_stat_byte3 = (char far *)0x00400096UL;
  566.         if (0x10 & *kbd_stat_byte3)
  567.             /* 101- or 102-key keyboard is installed */
  568.  
  569.     {PC Magazine}'s 15 Jan 1991 issue suggests on page 412 that "for
  570.     some clones [the above test] is not foolproof".  If you use this
  571.     method in your program you should provide the user some way to
  572.     override this test, or at least some way to tell your program to
  573.     assume a non-enhanced keyboard.  The {PC Magazine} article suggests
  574.     a different approach to determining the type of keyboard.
  575.  
  576. Q309. How can I tell if input, output, or stderr has been redirected?
  577.  
  578.     Normally, input and output are associated with the console (i.e.,
  579.     with the keyboard and the screen, respectively).  If either is not,
  580.     you know that it has been redirected.  Some source code to check
  581.     this is available at the usual archive sites.
  582.  
  583.     If you program in Turbo Pascal, download the /pc/ts/tspa*.zip
  584.     collection of Turbo Pascal units from garbo; or from Simtel,
  585.     PD1:<MSDOS.TURBOPAS>TSPA*.ZIP.  (Choose TSPA3060.ZIP, TSPA3055.ZIP,
  586.     TSPA3050.ZIP, or TSPA3040.ZIP for Turbo Pascal 6.0, 5.5, 5.0, or 4.0
  587.     respectively.)  Source code is not included.  Also see the
  588.     information in garbo.uwasa.fi:/pc/ts/tsfaq*.zip Frequently Asked
  589.     Questions, the Turbo Pascal section.
  590.  
  591.     If you program in C, use isatty( ) if your implementation has it.
  592.     Otherwise, you can download PD1:<MSDOS.SYSUTL>IS_CON10.ZIP from
  593.     Simtel; it includes source code.
  594.  
  595.     Good references for the principles are {PC Magazine} 16 Apr 1991
  596.     (vol 10 nr 7) pg 374; Ray Duncan's {Advanced MS-DOS}, ISBN
  597.     1-55615-157-8, or Ralf Brown's interrupt list for INT 21 function
  598.     4400; and Terry Dettman and Jim Kyle's {DOS Programmer's Reference:
  599.     2d edition}, ISBN 0-88022-458-4, pp 602-603.
  600.  
  601. (continued in part 3)
  602. -- 
  603. Stan Brown, Oak Road Systems                      brown@Ncoast.ORG
  604. Cleveland, Ohio, USA
  605.